function diff = q_fun(m,param)

    if param.zeta>0 && (param.K>0)  
        diff=q_n(m,param.psi,param).*(m<param.m_h)+q_r(m,param.psi,param).*(m>=param.m_h).*(m<=param.m_e);
        diff((m>param.m_e)) = q_e(m(m>param.m_e),param.psi,param);
    else
        diff = q_g_fun(m,param);             
    end

end